Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigQuery: docs for Row.keys, items, values, and get functions. #4410

Merged
merged 2 commits into from
Nov 17, 2017

Conversation

tswast
Copy link
Contributor

@tswast tswast commented Nov 17, 2017

I forgot to ask for these in #4393 before I merged.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 17, 2017
@tswast tswast added the api: bigquery Issues related to the BigQuery API. label Nov 17, 2017
@@ -783,22 +783,38 @@ def __init__(self, values, field_to_index):
self._xxx_field_to_index = field_to_index

def values(self):
"""Return the values included in this row.

This comment was marked as spam.

This comment was marked as spam.

Examples:

>>> Row(('a', 'b'), {'x': 0, 'y': 1}).keys()
['x', 'y']
"""
keys = self._xxx_field_to_index.keys()
return keys

This comment was marked as spam.

@@ -808,18 +824,38 @@ def items(self):
return items

This comment was marked as spam.

This comment was marked as spam.

>>> Row(('a', 'b'), {'x': 0, 'y': 1}).get('z', default = '')
''
"""Return value for ``key`` if ``key`` is in the row, else
``default``.

This comment was marked as spam.

This comment was marked as spam.


Args:
key (str): The key of the column to access

This comment was marked as spam.

>>> Row(('a', 'b'), {'x': 0, 'y': 1}).get('x')
'a'

The default value is ``None`` when the key does not exist.

This comment was marked as spam.

This comment was marked as spam.

- Refactors items, keys to return iterators.
- Copies values to prevent mutating the original row object.
@dhermes
Copy link
Contributor

dhermes commented Nov 17, 2017

@tswast For future PRs, can you squash while merging the PR? It's harder to review a PR when I can't tell what you changed when squashing. (Though I definitely feel the seem way, I squash locally a lot because for some reason I care about commit log clutter, even though we are 5500+ commits in to this project.)

Return keys as of a dict:
>>> Row(('a', 'b'), {'x': 0, 'y': 1}).keys()
['x', 'y']
return copy.deepcopy(self._xxx_values)

This comment was marked as spam.

This comment was marked as spam.

]
return items
for key, index in six.iteritems(self._xxx_field_to_index):
yield (key, copy.deepcopy(self._xxx_values[index]))

This comment was marked as spam.

Copy link
Contributor

@dhermes dhermes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, though I'm a bit "sad" about the copies. (They seem necessary evils, but still evils.)

@tswast
Copy link
Contributor Author

tswast commented Nov 17, 2017

Yeah, it is a bit sad about copies. There's definitely a trade-off between safety and performance. Probably better to err on the side of safety.

@tswast tswast merged commit f3e745e into googleapis:master Nov 17, 2017
@tswast tswast deleted the bq-row-docs branch November 17, 2017 18:37
@dhermes
Copy link
Contributor

dhermes commented Nov 17, 2017

@tswast Looks like the generators broke the build: https://circleci.com/gh/GoogleCloudPlatform/google-cloud-python/4288

Shall we revert, then re-submit this PR but push the branch to the GoogleCloudPlatform remote so system tests run?

@tswast
Copy link
Contributor Author

tswast commented Nov 17, 2017

Yeah, let's revert. I didn't think to check the system tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the BigQuery API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants